package com.example.springcloud.provider.student.service.impl;

import com.example.springcloud.common.entity.Student;
import com.example.springcloud.provider.student.dao.StudentDao;
import com.example.springcloud.provider.student.service.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentDao studentDao;

    @Override
    public void addStudent(Student student) {
        studentDao.insertStudent(student);
    }

    @Override
    public Student findStudentById(int id) {
        return studentDao.searchOneById(id);
    }

    @Override
    public List<Student> findAllStudents() {
        return studentDao.searchAll();
    }

    @Override
    public void updateStudent(Student student) {
        if (!studentDao.updateStudent(student)) {
            throw new RuntimeException("修改失败");
        }
    }

    @Override
    public void deleteStudent(int id) {
        if (!studentDao.deleteById(id)) {
            throw new RuntimeException("删除失败");
        }
    }
}
